<?php
/* SVN FILE: $Id: app_class_ibmarket.php 222 2009-09-16 20:07:22Z supersmashbrothers $ */
/**
* ibMarket 2
* IP.Board 3.0
* ibMarket application loading file
*
* @author $Author: supersmashbrothers $
* @copyright $Copyright$
* @version $Revision: 222 $
* @lastrevision $Date: 2009-09-16 20:07:22 +0000 (Wed, 16 Sep 2009) $
* @modifiedby $LastChangedBy: supersmashbrothers $
* @lastmodified $LastChangedDate: 2009-09-16 20:07:22 +0000 (Wed, 16 Sep 2009) $
* @filesource $URL: http://ipb-ibmarket.googlecode.com/svn/ibmarket2/trunk/admin/applications_addon/other/ibmarket/app_class_ibmarket.php $
*/

class app_class_ibmarket
{
	/**
	 * Constructor
	 *
	 * @access	public
	 * @param	object		ipsRegistry reference
	 * @return	void
	 */
	public function __construct( ipsRegistry $registry )
	{
		if(!class_exists('marketRegistry'))
		{
			require_once( IPSLib::getAppDir('ibmarket')."/sources/marketRegistry.php");
		}
	}
	
	public function afterOutputInit()
	{
		if(ipsRegistry::member()->member_id != 0 && IN_ACP == 0)
		{
			ipsRegistry::member()->setProperty('market_deduct', numbers::divide(numbers::subtract(100,ipsRegistry::member()->getProperty('g_market_discount')), 100));
		}
		else
		{
			ipsRegistry::member()->setProperty('market_deduct', 1);
		}
		if(ipsRegistry::member()->member_id == 0)
		{
			ipsRegistry::member()->setProperty('market_tax', 0);
		}
		marketRegistry::__setup();
		if(IN_ACP == 0)
		{
			marketRegistry::getInventoryItem(ipsRegistry::member()->member_id);
		}
	}
}

abstract class marketPublicCommand extends ipsCommand
{
	public function execute( ipsRegistry $registry )
	{
		$this->makeRegistryShortcuts( $registry );
		
		$this->registry->getClass('class_localization')->loadLanguageFile( array( 'public_market' ) );
		
		if($this->memberData['member_group_id'] == $this->settings['admin_group'])
		{
			$this->settings['market_on'] = 1;
			$this->memberData['g_market_view'] = 1;
			$this->memberData['g_market_use'] = 1;
			$this->memberData['market_access'] = -1;
		}
		elseif($this->memberData['member_id'] == 0)
		{
			$this->memberData['g_market_view'] = $this->settings['market_guests'];
			$this->memberData['g_market_use'] = 0;
			$this->memberData['market_access'] = -1;
		}
		
		if($this->memberData['member_id'] && $this->memberData['market_access'] != -1)
		{
			$this->memberData['g_market_view'] = $this->memberData['market_access'];
		}
		if(!$this->settings['market_on'] && $this->memberData['member_group_id'] != $this->settings['admin_group'])
		{
			$this->registry->getClass('output')->showError('market_offline');
		}
		if(!$this->settings['market_guests'] && !$this->memberData['member_id'])
		{
			$this->registry->getClass('output')->showError('market_noguest');
		}
		if(!$this->memberData['g_market_view'])
		{
			$this->registry->getClass('output')->showError('market_noview');
		}
		
		$this->doExecute( $registry );
	}
}